package com.angel.architecture.persistence.beans;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;

import org.apache.commons.lang.ArrayUtils;

import com.angel.architecture.persistence.base.PersistentObject;

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType=DiscriminatorType.STRING, length=10)
@DiscriminatorValue("simple")
public class Role extends PersistentObject {

	private static final long serialVersionUID = 399044139533517561L;

	@Column(nullable=false, unique=true)
	private String name;

	private String description;

	public Role(){
		super();
	}

	public Role(String name, String description) {
		this(name);
		this.setDescription(description);
	}
	
	public Role(String name) {
		this.name = name;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}
	public boolean canAccessService(String[] desiredRoles) {
		return ArrayUtils.contains(desiredRoles, this.name);
	}

	public boolean canChangeEntity(String[] desiredRoles, PersistentObject entity) {
		return ArrayUtils.contains(desiredRoles, this.name);
	}
}